// import React, { useEffect } from 'react'
// import { useLocation, useNavigate } from 'react-router-dom'

// function useAuthrouter() {


// // 白名单
//     const nav = useNavigate()
//     const { pathname } = useLocation()
//     useEffect(() => {
//         const token = localStorage.getItem('token')
//         const bai = ['/index/home']
//         if (!token && bai.includes(pathname)) {
//             nav('/')
//         }
//     }, [])
// }

// export default useAuthrouter

// import React, { useEffect } from 'react'
// import { useLocation, useNavigate } from 'react-router-dom'

// function useAuthrouter() {
//     const { pathname } = useLocation()
//     const nav = useNavigate()

//     useEffect(() => {
//         const token = localStorage.getItem('token')
//         const bai = ['/index/home']
//         if (!token && bai.includes(pathname)) {
//             nav('/')
//         }
//     }, [])
// }

// export default useAuthrouter


import React, { useEffect } from 'react'
import { useLocation, useNavigate } from "react-router-dom"

function useAuthrouter() {

    const nav = useNavigate()
    const { pathname } = useLocation()
    useEffect(() => {
        const token = localStorage.getItem('token')
        const bai = ['/index/home', '/index/user/useradd']

        if (!token && bai.includes(pathname)) {
            nav('/')
        }
    }, [])
}

export default useAuthrouter









